package cn.highedu.spring.aop;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class AopTest {
    private ApplicationContext context;
    @BeforeEach
    public void createContext() {
        context = new AnnotationConfigApplicationContext(ContextConfig.class);
    }

    @Test
    public void test1() {
        UserDao userDao = context.getBean("userDao", UserDao.class);
        int n = userDao.save(1);
        System.out.println(n);
        // userDao.get();
    }

    @Test
    public void test2() {
        UserDao userDao = context.getBean("userDaoProxy", UserDao.class);
        userDao.delete();
        userDao.update();
    }
    @Test
    public void testProxy() {
        UserDao userDao = context.getBean("userDao", UserDao.class); // 目标类对象
        LoggerProxy loggerProxy = context.getBean("loggerProxy", LoggerProxy.class);// 代理类
        UserDao userDaoProxy = (UserDao) loggerProxy.getProxy(userDao);// 代理对象
        //userDaoProxy.save();
    }

    @Test
    public void test3() {
        UserDao userDao = context.getBean("userDao", UserDao.class);
        //userDao.save(1);
        userDao.delete();

        userDao.get();
    }
}
